<?php
$this->widget('ext.mylib.widgets.Gridview.DGridView', array(
    'id'           => 'content-grid',
    'dataProvider' => $data,

    'filter' => $model,
    'columnGroup' => array(50, 0, 100, 25),
    'htmlOptions' => array('class'      => 'hastable'),
    'myPageSize' => 10,

    'columns' => array(
        array(
            'name'        => 'id',
            'htmlOptions' => array('style'  => 'text-align:center;'),
            'filter' => CHtml::activeTextField($model, 'id', array(
                'class' => 'text full',
                'style' => 'width: 85%; padding:3px 5px;',
            )),
        ),
        array(
            'name'   => 'title',
            'filter' => CHtml::activeTextField($model, 'title', array(
                'class' => 'text full',
                'style' => 'width: 98%; padding:3px 5px;',
            )),
        ),
        array(
            'name'   => 'type_id',
            'filter' => catMenu($model),
            'value'  => 'DNewsletterType::model()->getTypeText($data->type_id)',
        ),
        array(
            'header'            => '',
            'type'              => 'raw',
            'value'             => 'CHtml::link("assign", "javascript:void(0)", array('
                . '"class" => "assign link",'
                . '"ref"   => "news/info/$data->id-$data->title_seo",'
                . '))',
            'headerHtmlOptions' => array('width'       => '50px'),
            'htmlOptions' => array('style' => 'text-align:center;'),
        ),
    ),
));

function catMenu($model) {
    $obj = new ArrayToDropDownList();
    
    $obj->model = $model;
    $obj->attribute = 'type_id';
    $obj->data = DNewsletterType::model()->getMenu();
    $obj->disableParent = true;
    $obj->emptyOption = Yii::t('DadminModule.app', 'category');
    $obj->selected = $model->getAttribute('type_id');
    $obj->htmlOptions = array(
        'class' => 'select',
        'style' => 'width: 100px;',
    );

    ob_start();
    $obj->run();
    $html = ob_get_contents();
    ob_end_clean();

    return $html;
}
?>
<div class="clearfix"></div>
<script type="text/javascript">
    $(document).on("click", ".assign", function(){
        var link = $(this).attr('ref');
        //  parent.$('#frameForm').contents().find('#Menu_link').val(link);
        parent.$('#dialogLinks')
        .data('link', link)
        .trigger('assignLink')
        .dialog('close');
    });  
</script>